/*
 * ForInstructionDescription.java
 * 
 * last update: 16.01.2010 by Stefan Saru
 * 
 * author:	Power(power@kermit.cs.pub.ro)
 * 
 * Obs:
 */


package engine;

class ForInstructionDescription extends InstructionDescription{
	ExpressionDescription ede;
	InstructionDescription id, idi, idc;

	// ii == initial instruction (procassignment)
	// ede ==  condition to end
	// ic = cycle instruction
	// id = block instruction
	ForInstructionDescription(int db, int line, NameSpaceDescription nsd,
			InstructionDescription ii,
			ExpressionDescription ede,
			InstructionDescription ic,
			InstructionDescription id){
		super(db, line, nsd);
		idi = ii;  this.ede = ede; idc = ic;  this.id = id;
	}

	DefaultInstruction instantiate(NameSpace ns)throws ParseException{

		Expression edeInstance;
		try{
			edeInstance = ede.instantiate(ns);
		}catch(ParseException ex){
			xConsole.dumpStack(ex);
			throw new ParseException(super.toString() + " error:" + ex);
		}

		return new ForInstruction(ns, delayBefore, this,
				idi == null ? null : idi.instantiate(ns),
						ede == null ? null : edeInstance,
								idc == null ? null : idc.instantiate(ns),
										id == null ? null : id.instantiate(ns),
												next == null ? null : next.instantiate(ns));
	}

	public String toString(){
		return super.toString() + "for( " +
		(idi == null ? "" : "..") + "; " + ede + "; " +
		(idc == null ? "" : "..") + " )";
	}
}

